package com.oig.sys.auth.service.impl;

import com.oig.sys.auth.dao.ITbUserColumnDao;
import com.oig.sys.auth.service.ITbUserColumnService;
import com.oig.sys.auth.entity.TbUserColumn;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wuxl
 */
@Service
@Slf4j
public class TbUserColumnServiceImpl implements ITbUserColumnService {

	private final ITbUserColumnDao tbUserColumnDao;

	@Autowired
	public TbUserColumnServiceImpl( ITbUserColumnDao tbUserColumnDao){
		 this.tbUserColumnDao = tbUserColumnDao;
	}

	@Override
	public List<Integer> findAllUCResourceIdByUserId(Integer userId) {
		log.debug("query resourceId by userId={}",userId);
		return this.tbUserColumnDao.findAllUCResourceIdByUserId(userId);
	}

	@Override
	public List<Integer> findUserColumnIdByResourceId(Integer resourceId){
		log.debug("query user column id where resourceId ={}",resourceId);
		return this.tbUserColumnDao.findIdByResourceId(resourceId);
	}


	@Override
	public TbUserColumn getById(Integer id) {
		return this.tbUserColumnDao.getTbUserColumnById(id);
	}
	@Override
	public TbUserColumn getByResourceIdAndUserId(Integer resourceId, Integer userId) {
		return this.tbUserColumnDao.getByResourceIdAndUserId(resourceId, userId);
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public TbUserColumn addUserColumn(Integer resourceId, Integer userId) {
		TbUserColumn userColumn = new TbUserColumn();
		userColumn.setResourceId(resourceId);
		userColumn.setUserId(userId);
		this.tbUserColumnDao.save(userColumn);
		return userColumn;
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public void deleteByIds(List<Integer> idList) {
		this.tbUserColumnDao.deleteByIdList(idList);
	}

	@Override
	public List<Integer> findUserIdByResourceId(Integer resourceId) {
		return tbUserColumnDao.findUserIdByResourceId(resourceId);
	}

	@Override
	public List<TbUserColumn> getByResourceId(Integer resourceId) {
		return tbUserColumnDao.getByResourceId(resourceId);
	}
}
